/**
 * Created by henian.xu on 2017/3/28.
 *
 */

var commentUm = UE.getEditor('commentUm', {
  autoFloatEnabled: false,
  //这里可以选择自己需要的工具按钮名称,此处仅选择如下七个
  toolbars: [['emotion']],
  //focus时自动清空初始化时的内容
  autoClearinitialContent: true,
  //关闭字数统计
  wordCount: false,
  //关闭elementPath
  elementPathEnabled: false,
  initialFrameWidth: '100%',
  //默认的编辑区域高度
  initialFrameHeight: 80,
  //更多其他参数，请参考umeditor.config.js中的配置项
});
var replyUE = {};

function creatUE(id) {
  replyUE[id] = UE.getEditor(id, {
    autoFloatEnabled: false,
    //这里可以选择自己需要的工具按钮名称,此处仅选择如下七个
    toolbars: [['']],
    //focus时自动清空初始化时的内容
    autoClearinitialContent: true,
    //关闭字数统计
    wordCount: false,
    //关闭elementPath
    elementPathEnabled: false,
    initialFrameWidth: '100%',
    //默认的编辑区域高度
    initialFrameHeight: 80,
    //更多其他参数，请参考umeditor.config.js中的配置项
  });
}

//jQ 缓存
var
    $comment = $('.comment'),
    $commentList = $('.comment-list');

//查看回复点击事件
$commentList.on('click', '.look-reply-btn', function(e) {
  var
      $this = $(this),
      $desc = $this.closest('.desc'),
      $replyBox = $desc.children('.reply-box');
  if ($replyBox.is(':visible')) {
    $replyBox.hide();
  } else {
    $replyBox.show();
  }
});

//回复点击事件
$commentList.on('click', '.reply-btn', function(e) {
  var
      $this = $(this),
      $desc = $this.closest('.desc'),
      $replyEdit = $desc.children('.reply-edit'),
      $replyEditor = $replyEdit.children('.replyEditor'),
      id = $replyEditor.attr('id');

  if (!id) {
    id = 'replyEditor' + new Date().getTime();
    $replyEditor.attr('id', id);
    creatUE(id);
  }

  if ($replyEdit.is(':visible')) {
    $replyEdit.hide();
  } else {
    $replyEdit.show();
  }
});

//评论发送
$comment.on('click', '.send-btn', function(e) {
//在这里写 ajax 提交;
  console.log(commentUm.getContent());
});

//回复列表发送
$commentList.on('click', '.send-btn', function(e) {
  var
      $this = $(this),
      $replyEditor = $this.siblings('.replyEditor'),
      id = $replyEditor.attr('id');

  //在这里写 ajax 提交;
  console.log(replyUE[id].getContent());

});

// 视频播放

var $articleBody = $('.article-body'),
    $video = $articleBody.find('video'),
    idCount = 0;

$video.each(function() {
  idCount++;
  var $this = $(this),
      source = $this.attr('src');

  var $node = $('<div class="prism-player" id="video_' + idCount + '"></div>');

  $this.after($node);
  $this.remove();

  var player = new Aliplayer({
    id: 'video_' + idCount,
    width: '100%',
    autoplay: false,
    //支持播放地址播放,此播放优先级最高
    source: source,
  }, function(player) {
    console.log('播放器创建好了。');
  });
});












